package com.bw.a525zy.New

import androidx.paging.PagingSource
import androidx.paging.PagingState
import com.bw.base.entity.NewEntityItem
import com.bw.base.net.ApiServer

@Suppress("UNUSED_EXPRESSION")
class NewSure (val apiServer: ApiServer):PagingSource<Int,NewEntityItem>() {
    override fun getRefreshKey(state: PagingState<Int, NewEntityItem>): Int? {
        return null
    }

    override suspend fun load(params: LoadParams<Int>): LoadResult<Int, NewEntityItem> {
      try {
          val i = params.key ?: 0
          val new = apiServer.getNew()
          val i1 = if (new.data.size == 10) i + 1 else null
         return LoadResult.Page(new.data,null,i1)
      }catch (e:Exception){
          return LoadResult.Error(e)
      }

    }
}